



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiAdmin.std/src/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiAdmin.std/src/layuiadmin/style/admin.css" media="all">
</head>
<body>



<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                    <div class="layui-form">

                        <div class="layui-form-item">
                            <label class="layui-form-label">选择表：</label>
                            <div class="layui-input-block">
                                <select class="layui-select" id="tb_name" name="tb_name" lay-verify="required">
                                    <option value="">选择表</option>
                                    {volist name="tb_list" id="tb"}
                                    <option value="{$tb}">{$tb}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="btn_save" id="btn_save">生成代码</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>

        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-tab">
                        <ul class="layui-tab-title">
                            <li class="layui-this">controller</li>
                            <li>edit.html</li>
                            <li>index.html</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <textarea class="layui-textarea" id="txtController" style="height: 400px"></textarea>
                            </div>
                            <div class="layui-tab-item">
                                <textarea class="layui-textarea" id="txtEdit" style="height: 400px"></textarea>
                            </div>
                            <div class="layui-tab-item">
                                <textarea class="layui-textarea" id="txtIndex" style="height: 400px"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/layuiAdmin.std/src/layuiadmin/layui/layui.js"></script>
<script>
    var tree;
    var layer;
    var util;
    var select;
    var $;
    var form;


    function save(field) {
        layer.confirm('确定生成CURD？', function(index) {
            $('#btn_save').hide()
            $.ajax({
                url: 'create_curd',
                type: 'POST',
                data: field,
                dataType: 'json',
                success: function (data) {
                    if (data.code == '0') {
                        $('#txtController').val(data.data.ctrl)
                        $('#txtEdit').val(data.data.edit)
                        $('#txtIndex').val(data.data.index)
                        layer.msg('创建成功', { icon: 1, time: 1000 }, function () {
                            layer.closeAll()

                            $('#btn_save').show()
                        });

                    } else {
                        layer.msg(data.msg, { icon: 5, time: 2000 });

                        $('#btn_save').show()
                    }
                }
            });
        });
    }



    layui.config({
        base: '/static/layuiAdmin.std/src/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tree', 'util', 'customSelect'], function(){
        tree = layui.tree
        layer = layui.layer
        util = layui.util
        select = layui.customSelect
        $ = layui.$
        form = layui.form



        $('#sex').val()
        form.render()

        form.on('submit(btn_save)', function(obj){

            save(obj.field)

        });
    });
</script>

</body>
</html>